<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
    	<link href="Public/css/bootstrap.min.css" rel="stylesheet">
    	<link href="Public/css/common.css" rel="stylesheet">
		<script src="Public/js/jquery-1.7.2.min.js"></script>
		<script src="Public/js/bootstrap.min.js"></script>
    	<script type="text/javascript">
		   $(function(){
		      $('#myTab li:eq(0) a').tab('show');
		   });
		</script>
	    <!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	</head>
	
	<body>
		<form action="" method="post" enctype="multipart/form-data">

	  <ul id="myTab" class="nav nav-tabs">
	   <li class="active"><a href="#tab1" data-toggle="tab">
	      基本设置</a>
	   </li>
	   <li><a href="#tab2" data-toggle="tab">规格属性</a></li>
	   <li><a href="#tab3" data-toggle="tab">图片设置</a></li>
	   <li><a href="#tab4" data-toggle="tab">产品详情</a></li>
	   <li><a href="#tab5" data-toggle="tab">售后服务</a></li>
	   
	   <li class="dropdown">
	      <a href="#" id="myTabDrop1" class="dropdown-toggle" 
	         data-toggle="dropdown"> 确定  <b class="caret"></b>
	      </a>
	      <ul style="padding: 5px;" class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
	         <li><button class="btn btn-primary btn-block" type="submit"> 确定 </button>
	         </li>
	         <li><button style="margin-top: 5px;" class="btn btn-default btn-block" type="reset"> 清空 </button>
	         </li>
	      </ul>
	   </li>
	</ul>
<div id="myTabContent" class="tab-content">
   <div class="tab-pane fade in active" id="tab1">
		<div class="alert alert-success">基本设置</div>
		<table class=''>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">商品名称</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gname']?>" name="gname">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">货号</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gnum']?>" name="gnum">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">单位</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gunit']?>" name="gunit">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">市场价</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gmarketprice']?>" name="gmarketprice">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">商城价</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gshopprice']?>" name="gshopprice">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">总库存</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gcount']?>" name="gcount">								
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">点击量</label></td>
							<td style="padding-right: 20%;">
								<input id="exampleInputEmail1" class="form-control" type="text" value="<?php echo $olddata[0]['gclick']?>" name="gclick">
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">所属分类</label></td>
							<td style="padding-right: 50%;">
								<select name="category_cid" class="form-control">
									<option value="">请选择</option>
									<?php foreach (Data::tree(Db::table('category')->get(),'cname') as $v2){?>
										<option <?php if($v2['cid']==$olddata[0]['category_cid']){?>
                selected
               <?php }?> value="<?php echo $v2['cid']?>" tid="<?php echo $v2['type_tid']?>"><?php echo $v2['_name']?></option>
									<?php }?>
								</select>
							</td>
			</tr>
			<tr class="info">
							<td><label style="float: right;padding-right: 10%;" for="exampleInputEmail1">所属品牌</label></td>
							<td style="padding-right: 50%;">
								<!--载入品牌-->
								<select name="brand_bid" class="form-control">
									<option value="">请选择</option>	
									<?php foreach (Db::table('brand')->get() as $v){?>
										<option <?php if($v['bid']==$olddata[0]['brand_bid']){?>
                selected
               <?php }?> value="<?php echo $v['bid']?>"><?php echo $v['bname']?></option>
									<?php }?>
								</select>
							</td>
			</tr>
		</table>
   </div>
   <div class="tab-pane fade" id="tab2">
		<script type="text/javascript">
		$(function(){
			$('[name=category_cid]').change(function(){
	//			抓取选中的类型id
				var tid = $('option:selected').attr('tid');
				$.ajax({
					type:"post",
					url:"<?php echo U('getTypeAttr')?>",
					data:{id:tid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData,function(k,v){
							//规格
							if(v.taclass == 1){
									spec += '<tr class="info"><td>'+v.taname+'</td><td><select name="spec['+v.taid+'][value][]" id=""><option value="">请选择</option>';
									$.each(v.tavalue, function(kk,vv) {    
										spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
											});
										spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" id="" /></td><td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							}else{
							//属性
							attr += '<tr class="info"><td>'+v.taname+'</td><td><select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
							$.each(v.tavalue, function(kk,vv) {    
								attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
													});
									attr += '</select></td></tr>';
								}
						})
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				});
			})
			
			//点击添加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var parentsTr = $(this).parents('tr');
				//把父级的tr克隆复制
				var cloneTr = parentsTr.clone();
				cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
				//插入下一行
				parentsTr.after(cloneTr);
			})
			//删除规格
			$('.remove-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
		})
	</script>
	<div class="alert alert-success">商品规格</div>
		<table class="table table-bordered table-hover" id='spec' class="info">
			<?php foreach ($typeattr as $k1=>$v1){?>						
			<tr class="info">
				<td><?php echo $v1['taname']?></td>
				<td>
					<select name="spec[<?php echo $v1['taid']?>][value][]" id="">
						<option value="">请选择</option>
						<?php foreach (explode(',',$v1['tavalue']) as $v3){?>
							<option value="<?php echo $v3?>"><?php echo $v3?></option>
						<?php }?>
					</select>
				</td>
				<td>附加价格：<input type="text" name="spec[<?php echo $v1['taid']?>][price][]" id="" /></td>
				<td>
					<span class="btn btn-success add-spec">增加规格</span>
				</td>
			</tr>
			<?php }?>
			<?php foreach ($all as $k1=>$v1){?>
				<?php foreach ($v1['gavalue'] as $k2=>$v2){?>
			<tr class="info">
				<td><?php echo $v1['taname']?></td>
				<td>
					<select name="spec[<?php echo $v1['taid']?>][value][]" id="">
						<?php foreach ($v1['tavalue'] as $v3){?>
							<option <?php if($v3==$v2){?>
                selected="selected" 
               <?php }?>value="<?php echo $v3?>"><?php echo $v3?></option>
						<?php }?>
					</select>
				</td>
				<td>附加价格：<input type="text" name="spec[<?php echo $v1['taid']?>][price][]" id="" value="<?php echo $v1['gaadd'][$k2]?>"/></td>
				<td>
					<span class="btn remove-spec btn-danger">删除规格</span>
				</td>
			</tr>
				<?php }?>
			<?php }?>
		</table>
	<div class="alert alert-success">商品属性</div>
		<?php $typeattr = Db::table('typeattr')->where("type_tid={$olddata[0]['type_tid']} and taclass=0")->get(); ?>
		<?php 
		$goodsattr = Db::table('goodsattr')->where("goods_gid={$olddata[0]['gid']} and gaadd= 'em'")->get();
		$old = array();
			foreach ($goodsattr as $value) {
				$old[] = $value['gavalue'];
			}
			?>
		<table class="table table-bordered table-hover" id='attr' class="info">
		<?php foreach ($typeattr as $v1){?>
			<tr class="info">
				<td><?php echo $v1['taname']?></td>
				<td><select name="attr[<?php echo $v1['taid']?>]" id="">
					<?php foreach (explode(',',$v1['tavalue']) as $v3){?>
						<option <?php foreach ($old as $oldv){?> <?php if($oldv==$v3){?>
                 selected 
               <?php }?> <?php }?> value="<?php echo $v3?>"><?php echo $v3?></option>
					<?php }?>
					</select>
				</td>
			</tr>
		<?php }?>
		</table>
   </div>
   <div class="tab-pane fade" id="tab3">
   	<?php $goodsdes = Db::table('goodsdes')->where("goods_gid={$olddata[0]['gid']}")->get(); ?>
    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
<div class="alert alert-success">列表图片</div>
	<div class="form-group">
		
		<div lab="uploadFile">
	    <input id="a" type="file" multiple="true">
	    <span>列表图片 类型: *.jpg,*.png,*gif; 大小: 2000KB 列表图片只能上传一张</span>
	    <script type="text/javascript">
	        $(function() {
	            $('#a').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeDesc' : '上传文件',//上传描述
	                'fileTypeExts' : '*.jpg;*.gif;*.png',
	                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
	                'uploader' : '<?php echo U('uploadgpic')?>',
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 1,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='gpic' value='"+data.path+"'/></li>";
	                    $("#uploadLista1 ul").html(li);
	                }
	            });
	        });
	    </script>
	    <div id="uploadLista1">
	        <ul>

	        	<li ><img src='<?php echo $olddata[0]['gpic']?>'/><input type='hidden' name='gpic' value='<?php echo $olddata[0]['gpic']?>'/></li>

	        </ul>
	    </div>
	    </div>
	</div>

	<div class="alert alert-success">商品图片</div>
	<div class="form-group">
		<div lab="uploadFile">
	    <input id="b" type="file" multiple="true">
	    <span>商品图片 类型: *.jpg,*.png,*gif; 大小: 2000KB 单次最大数量: 5</span>
	    <script type="text/javascript">
	        $(function() {
	            $('#b').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeDesc' : '上传文件',//上传描述
	                'fileTypeExts' : '*.jpg;*.gif;*.png',
	                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
	                'uploader' : '<?php echo U('uploadgdpic')?>',
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 5,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='gdpic[]' value='"+data.path+"'/></li>";
	                    $("#uploadListb2 ul").prepend(li);
	                }
	            });
	        });
	    </script>
	    <div id="uploadListb2">
	        <ul>
	        <?php foreach (explode(',',$goodsdes[0]['gdpic']) as $v){?>
				<li ><img src='<?php echo $v?>'/><input type='hidden' name='gdpic[]' value='<?php echo $v?>'/></li>
			<?php }?>
	        </ul>
	    </div>
	    </div>
	</div>
   </div>
   <div class="tab-pane fade" id="tab4">
      <div class="form-group">
      	<div class="alert alert-success">产品详情</div>

			<!--调用百度编辑器-->
			<script id="gdcontent" type="text/plain" style="width:100%;height:500px;" name="gdcontent">
				<?php echo $goodsdes[0]['gdcontent']?>
			</script>
		    <script>
		        var ue = UE.getEditor('gdcontent');
		    </script>
		</div>
   </div>
   <div class="tab-pane fade" id="tab5">
      <div class="form-group">
	      	<div class="alert alert-success">售后服务</div>
			<!--调用百度编辑器-->
			<script id="gdaft" type="text/plain" style="width:100%;height:300px;" name="gdaft">
				<?php echo $goodsdes[0]['gdaft']?>
			</script>
		    <script>
		        var ue = UE.getEditor('gdaft');
		    </script>
		</div>
   </div>
   <div class="tab-pane fade" id="tab6">
      <div class="form-group">
	      	<div class="alert alert-success">售后服务</div>
			<!--调用百度编辑器-->
			<script id="gdaft" type="text/plain" style="width:100%;height:300px;" name="gdaft"></script>
		    <script>
		        var ue = UE.getEditor('gdaft');
		    </script>
		</div>
   </div>
</div>

		</form>
	</body>
</html>
